﻿@page "/"

@inject Blazored.LocalStorage.ILocalStorageService localStorage

<h3>LocalStorage</h3>

写入投币：<InputText @bind-Value="@writeContent"></InputText>
<hr />
<button @onclick="Write" class="btn btn-primary">写入</button>
<button @onclick="Read" class="btn btn-primary">读取</button>
<button @onclick="Remove" class="btn btn-primary">移除</button>
<hr />
<span>读取投币：@readContent</span>

@code {
    string writeContent;
    string readContent;

    bool isLoading = false;

    async void Write()
    {
        await localStorage.SetItemAsync("投币", writeContent);
    }

    async void Read()
    {
        if (await localStorage.ContainKeyAsync("投币"))
        {
            readContent = await localStorage.GetItemAsync<string>("投币");
        }
        else
        {
            readContent = "你还没投币";
        }
        await InvokeAsync(StateHasChanged);
    }

    async void Remove()
    {
        await localStorage.RemoveItemAsync("投币");
    }

}